//
//  HDGuideLastView.swift
//  HuaDaoPeifu
//
//  Created by liangyuanliangyuan on 16/5/13.
//  Copyright © 2016年 paiyipai. All rights reserved.
//

import UIKit

protocol lookSomethingDelegate: class {
    func lookSomething()
    func register()
    func login()
}


class HDGuideLastView: UIView {

    var lookButton: UIButton?
    var registerButton: UIButton?
    var loginButton:    UIButton?
    weak var lookDelegate: lookSomethingDelegate?
    let deviceName = UIDevice.current.name
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor(hex: 0x252a53)
        let view = UIImageView(frame: UIScreen.main .bounds)
        if deviceName == "iPhone 4s" {
            view.image = UIImage(named: "引导页5－4s")
        }else {
            view.image = UIImage(named: "引导页5")
        }
        
        self.addSubview(view)
        lookButton = UIButton(type: .custom)
        lookButton?.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.1)
        lookButton?.setTitle("随便看看", for: UIControlState())
        loginButton?.setTitleColor(UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.5), for: UIControlState())
        lookButton?.titleLabel?.font = UIFont.systemFont(ofSize: 13)
        lookButton?.addTarget(self, action: #selector(lookAction), for: .touchUpInside)
        lookButton?.layer.masksToBounds = true
        lookButton?.layer.cornerRadius = 12
        self.addSubview(lookButton!)
        lookButton?.snp.makeConstraints({ (make) in
            make.right.equalTo(-20)
            make.top.equalTo(20)
            make.width.equalTo(75)
            make.height.equalTo(25)
        })
        
        let logoImg = UIImageView()
        logoImg.image = UIImage(named: "组-2")
        self.addSubview(logoImg)
        var topPadding: CGFloat
        if deviceName == "iPhone 4s" {
            topPadding = 58
        }else {
            topPadding = 132
        }
        logoImg.snp.makeConstraints { (make) in
            make.top.equalTo(topPadding)
            make.centerX.equalTo(self.snp.centerX)
            make.height.width.equalTo(84)
        }
        
        let appName = UILabel()
        appName.text = "速赔宝"
        if deviceName == "iPhone 4s" {
            appName.font = UIFont.systemFont(ofSize: 25)
        }else {
            appName.font = UIFont.systemFont(ofSize: 30)
        }
        
        appName.textColor = UIColor.white
        appName.shadowColor = UIColor(hex: 0x1c2045)
        appName.shadowOffset = CGSize(width: -1, height: 1)
        self.addSubview(appName)
        appName.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.top.equalTo(logoImg.snp.bottom).offset(13)
//            make.width.equalTo(90)
            make.height.equalTo(30)
        }
        
        let subTitle = UILabel()
        subTitle.text = "用速度与透明定义理赔"
        subTitle.font = UIFont.systemFont(ofSize: 18)
        subTitle.textColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.6)
        self.addSubview(subTitle)
        subTitle.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.top.equalTo(appName.snp.bottom).offset(20)
//            make.width.equalTo(180)
            make.height.equalTo(18)
        }
        
        
        //从下往上布局
        
        let copyright = UILabel()
        copyright.text = "Copyright © 2016 huadao"
        copyright.textColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 0.2)
        copyright.font = UIFont.systemFont(ofSize: 13)
        self.addSubview(copyright)
        copyright.snp.makeConstraints { (make) in
            make.centerX.equalTo(self.snp.centerX)
            make.bottom.equalTo(-25)
            make.height.equalTo(13)
        }
        
        registerButton = UIButton(type: .custom)
        registerButton?.setTitle("注册", for: UIControlState())
        registerButton?.addTarget(self, action: #selector(registerAction), for: .touchUpInside)
        registerButton?.layer.borderColor = UIColor.white.cgColor
        registerButton?.layer.borderWidth = 1
        registerButton?.layer.masksToBounds = true
        registerButton?.layer.cornerRadius = 2.5
        registerButton?.backgroundColor = UIColor.white
        registerButton?.setTitleColor(UIColor(hex: 0x313662), for: UIControlState())
        registerButton?.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        self.addSubview(registerButton!)
        registerButton?.snp.makeConstraints({ (make) in
            make.bottom.equalTo(copyright.snp.top).offset(-50)
            make.left.equalTo(37)
            make.right.equalTo(-37)
            make.height.equalTo(40)
        })

        loginButton = UIButton(type: .custom)
        loginButton?.layer.borderColor = UIColor.white.cgColor
        loginButton?.layer.borderWidth = 1
        loginButton?.layer.masksToBounds = true
        loginButton?.layer.cornerRadius = 2.5
        loginButton?.backgroundColor = UIColor.clear
        loginButton?.setTitle("登录", for: UIControlState())
        loginButton?.setTitleColor(UIColor.white, for: UIControlState())
        loginButton?.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        loginButton?.addTarget(self, action: #selector(loginActtion), for: .touchUpInside)
        self.addSubview(loginButton!)
        loginButton?.snp.makeConstraints({ (make) in
            make.left.equalTo(37)
            make.right.equalTo(-37)
            make.bottom.equalTo(registerButton!.snp.top).offset(-25)
            make.height.equalTo(40)
        })
        
        
    }
    
    //随便看看
    func lookAction() {
        lookDelegate?.lookSomething()
    }
    
    //注册
    func registerAction() {
        lookDelegate?.register()
    }
    
    //登录
    func loginActtion() {
        lookDelegate?.login()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
